package com.patrol.logisticsmanage.ui.message;

import android.os.Bundle;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.patrol.logisticsmanage.R;
import com.patrol.logisticsmanage.net.BaseObserver;
import com.patrol.logisticsmanage.net.BaseReponse;
import com.patrol.logisticsmanage.net.BaseRequest;
import com.patrol.logisticsmanage.ui.base.BaseActivity;
import com.patrol.logisticsmanage.ui.canteen.utils.GsonUtil;
import com.patrol.logisticsmanage.ui.home.Notice;
import com.patrol.logisticsmanage.ui.home.NoticeAdapter;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

@Route(path = "/app/NoticeActivity")
public class NoticeActivity extends BaseActivity {

    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.rcy_notice)
    RecyclerView rcyNotice;

    NoticeAdapter noticeAdapter;
    List<Notice> notices;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notice);
        ButterKnife.bind(this);

        tvTitle.setText("卫勤保障服务");
        notices = new ArrayList<>();

        rcyNotice.setLayoutManager(new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false));
        noticeAdapter = new NoticeAdapter(mContext,notices);
        rcyNotice.setAdapter(noticeAdapter);

        getData();
    }

    private void getData() {
            BaseRequest.getInstance().getApiServise().getNotice()
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new BaseObserver<Map>(mContext) {
                        @Override
                        public void onSuccess(BaseReponse<Map> baseReponse) {
                            List list = (List) baseReponse.getResults().get("records");
                            List<Notice> notices1 = GsonUtil.mapListToBeanList(list,Notice.class);
                            notices.addAll(notices1);
                            noticeAdapter.notifyDataSetChanged();
                        }

                        @Override
                        public void onCodeError(BaseReponse tBaseReponse) {
                        }

                        @Override
                        public void onFailure(Throwable e, boolean netWork) throws Exception {

                        }
                    });
    }
}
